#include<iostream>
#include "log.hpp"
#include"comm.hpp"
#include<string.h>

#define SIZE 1024
Log lg;
int main()
{
    Init it;
    lg.Enable(Screen);
    lg(Info,"Init done");
    //打开管道
    int fd=open(MYFIFO,O_RDONLY);
    printf("fd:%d",fd);
    if(fd==-1)
    {
        lg(Fatal,"error string:%s,error code:%d",strerror(errno),errno);
        exit(FIFO_OPEN_ERR);
    }
    lg(Info,"open done...");
    //开始读取数据
    while(true)
    {
        char buffer[SIZE];
        int n=read(fd,buffer,sizeof(buffer));
        if(n<0)
        {
            lg(Fatal,"strerr:%s,error code:%d",strerror(errno),errno);
            break;
        }
        if(n==0)
        {
            lg(Debug,"client quit,me too,strerr:%s,error code:%d",strerror(errno),errno);
            break;
        }
        else
        {
            buffer[n]=0;
            std::cout<<"client say#: "<<buffer<<std::endl;
        }
    }
    close(fd);
    return 0;
}